const RANDOM_NUMBER_KEY = 'localRandomNumber'
Page({
  data: {
    message: 'Hello ASCF',
    randomNumber: ''
  },

  readRandomNumber() {
    const localRandomNumber = has.getStorageSync(RANDOM_NUMBER_KEY, 0);
    this.setData({ randomNumber: localRandomNumber });
  },
  updateRandomNumber() {
    const randomNumber = Math.floor(Math.random() * 101);
    has.setStorageSync(RANDOM_NUMBER_KEY, randomNumber);
    this.setData({ randomNumber });
  },
  gotoPage2(event){
    console.log('pkl--event',event)
    has.navigateTo({
      url:'/pages/page2/pageIndex2'
    })
},
  gotoPage3(){
    has.navigateTo({
      url:'/pages/page3/page3'
    })
  },
  gorich(){
    has.navigateTo({
      url:'/pages/moveAblePage/moveAblePage'
    })
  },
  goShuaXinPage(){
    has.navigateTo({
      url:'/pages/pageShuaXin/pageShuaXin'
    })
  },
  golocationPage(){
    has.switchTab ({
      url:'/pages/getLocation/locationPage'
    })
  },
  govideo(){
    has.navigateTo ({
      url:'/pages/testbofang/testbofang'
    })
  },
  goDialogPage(){
    has.navigateTo ({
      url:'/pages/dialogComp/dialogComp'
    })
  },
  loadNewFornt(){
    const self = has.loadFontFace({
      family: 'myFamily',
      source: 'url("https://sungd.github.io/Pacifico.ttf")',
      success(res) {
        console.log("Font loaded successfully:" + res.status)
      },
      fail(res) {
        console.log("Faied to load the font" )
      },
      complete(res) {
        console.log('load the font complete')
      }
    })
},
  onLoad: function () {

    has.setTabBarBadge({
      index: 1,
      text: '2',
      success: function (res) {
        console.log('setTabBarBadge 回调成功：' + JSON.stringify(res));
      },
      fail: function (res) {
        console.log('setTabBarBadge 回调失败：' + JSON.stringify(res));
      },
      complete: function (res) {
        console.log('setTabBarBadge 回调完成：' + JSON.stringify(res));
      }
    });
    const query = has.createSelectorQuery();
    query.select('#test1').boundingClientRect();
    query.exec(function (res) {
      console.log('pkl-res = ', res);
    });
    console.log('pkl-index---')
    // this.data.paramA ='加载成功'// 页面参数 paramA 的值
    // this.data.paramB // 页面参数 paramB 的值
    has.onAppShow((res) =>{
      console.log('pkl---监听元服务切前台事件onLoadindex.js')
      console.log('监听元服务切前台事件', JSON.stringify(res))
    })
  },
  myEventListener: function(e){
    console.log(e.detail) // 自定义组件触发事件时提供的detail对象
  },
  getChildComponent:function(){
    const child = this.selectComponent('.my-component');
    console.log('pkl-child'+child,JSON.stringify(child));
  },
  savePhoto(){
    has.getImageInfo({
      src: 'https://appapi.chnmuseum.cn/uploadfiles/exhibit_img/20250123/202501230937407432.jpg', // 此处仅为样例，请开发者更换为可用图片资源地址
      success: (res) => {
        has.saveImageToPhotosAlbum({
          filePath: res.path,
          success(res) {
            console.log('saveImageToPhotosAlbum success');
          },
          fail(res) {
            console.log('saveImageToPhotosAlbum fail');
          },
          complete(res) {
            console.log('saveImageToPhotosAlbum complete');
          }
        });
      }
    });
  },
  getPhoneNumber(e){
    console.log('pkl-',e.detail.code)// 动态令牌
    console.log('pkl-',e.detail.errMsg)// 回调信息（成功失败都会返回）
    console.log('pkl-',e.detail.errCode)// 错误码（失败时返回）
  },
  gorvideo(){
    has.navigateTo({
      url:'/pages/videoPage/videoPage'
    })
  }

});